﻿/* 
 * 
 *    Project           A report class 
 *    Module Name       Excel Report 
 *    Author            Justin.Gu 
 *    Creation Date     [12/10/2016]      
 *     
 */
using System;
using System.Collections.Generic;
using SPCLib;
namespace Common
{
    public class CPKData
    {
        public string ItemName { get; set; }
        public double USL { get; set; }
        public double LSL { get; set; }
        public List<double> Datas { get; set; }
        public double[] MarkVals { get; set; }
        public bool UseMarkVals { get; set; }
        public List<GroupItem> getGroupItems()
        {
            List<GroupItem> gis = new List<GroupItem>();
            SPCLib.SPCFunctions spc = new SPCFunctions(Datas.ToArray(), USL, LSL);
            spc.UseMarkVals = UseMarkVals;
            spc.MarkVals = MarkVals;
            gis = spc.getGroupItems();
            return gis;
        }
        public Dictionary<string, double> GetCPKDictionary()
        {
            Dictionary<string, double> kvs = new Dictionary<string, double>();
            SPCLib.SPCFunctions spc = new SPCFunctions(Datas.ToArray(), USL, LSL);
            kvs.Add("CL", Math.Round(spc.getCL(), 3));
            kvs.Add("LCL", Math.Round(spc.getLCL(), 3));
            kvs.Add("UCL", Math.Round(spc.getUCL(), 3));
            kvs.Add("SL", Math.Round(spc.getSL(), 3));
            kvs.Add("LSL", Math.Round(spc.getLSL(), 3));
            kvs.Add("USL", Math.Round(spc.getUSL(), 3));
            kvs.Add("Max", Math.Round(spc.SPCMax(), 3));
            kvs.Add("Mean", Math.Round(spc.SPCMean(), 3));
            kvs.Add("Min", Math.Round(spc.SPCMin(), 3));
            kvs.Add("Range", Math.Round(spc.SPCRange(), 3));
            kvs.Add("CP", Math.Round(spc.SPCCp(), 3));
            kvs.Add("CPL", Math.Round(spc.SPCCpl(), 3));
            kvs.Add("CPU", Math.Round(spc.SPCCpm(), 3));
            kvs.Add("CPK", Math.Round(spc.SPCCpk(), 3));
            kvs.Add("StdDev", Math.Round(spc.SPCStdDev(), 3));
            return kvs;
        }
        public double[][] GetNormalArray()
        {
            SPCLib.SPCFunctions spc = new SPCFunctions(Datas.ToArray(), USL, LSL);
            return spc.NormalStepUpperLowerMidCountNormCumu();
        }
        public double[][] GetBarArray()
        {
            SPCLib.SPCFunctions spc = new SPCFunctions(Datas.ToArray(), USL, LSL);
            spc.setHistogramGroupNumber(7);
            return spc.HistogramStepUpperLowerMidCountNormCumu();
        }
    }
}